/**
 * 调用函数，返回action对象，也叫做同步的action对象
 */
import { getMenuList } from '../api/home'

export const add = payload => {
  return {
    type: 'ADD',
    payload
  }
}

export const minus = payload => {
  return {
    type: 'MINUS',
    payload
  }
}

export const ride = payload => {
  return {
    type: 'RIDE',
    payload
  }
}

export const asyncRide = payload => {
  return dispatch => {
    setTimeout(() => {
      dispatch(ride(payload))
    }, 1000)
  }
}

export const setMenu = payload => {
  return {
    type: 'SET_MENU',
    payload
  }
}

export const getMenuListData = () => {
  return async dispatch => {
    const res = await getMenuList()
    console.log(res)
    dispatch(setMenu(res.data))
  }
}
